//
//  HMDocListController.m
//  仿真项目开发
//
//  Created by LZH on 2017/3/22.
//  Copyright © 2017年 B.HOPE. All rights reserved.


#import "HMDocListController.h"
#import "HMDoctorListModel.h"
#import "HMDoctorListCell.h"
#import "HMDocDetailController.h"

#import "HMDocDetailModel.h"
#import "HMDocRequireModel.h"
#import "HMDocIntroduceModel.h"

#import "MJRefresh.h"
#import "HMbounceTool.h"
@interface HMDocListController ()

//医生列表模型数组
@property (strong,nonatomic)NSArray<HMDoctorListModel*>*docList;



//医生详情模型数组
@property(strong,nonatomic)NSArray<HMDocDetailModel *> *details;


//医生简介模型数组
@property(strong,nonatomic)NSArray<HMDocIntroduceModel *> *intros;

// 医生接诊条件模型数组
@property(strong,nonatomic)NSArray<HMDocRequireModel *> *requires;


@end

static NSString*DOCCELL=@"AttDocCell";
@implementation HMDocListController


-(NSArray*)docList{
    if (_docList==nil) {
        _docList=[NSArray array];
    }
    return _docList ;
}

- (void)viewDidLoad{
    [super viewDidLoad];
    [self setupUI];
    
}

- (void)awakeFromNib {
    
    [super awakeFromNib];
    [self setupUI];
}

- (void)setupUI {
    
    
    //注册cell
    UINib *nib = [UINib nibWithNibName:@"HMDoctorListCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:DOCCELL];
    
    //设置行高
    self.tableView.rowHeight = 130;

    //加载数据
    [self loadData];
    
    __weak typeof(self) weakSelf = self;
    //下拉刷新
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        //刷新完成时间
        [NSThread sleepForTimeInterval:1.0];
        [weakSelf.tableView.mj_header endRefreshing];
        [HMbounceTool CKLShowSVSuccessTitle:@"加载完成" andTime:0.8];
    }];
    //上拉刷新
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
       
        //刷新完成时间
        [NSThread sleepForTimeInterval:1.0];
        
        [weakSelf.tableView.mj_footer endRefreshing];
        [HMbounceTool CKLShowSVSuccessTitle:@"加载完成" andTime:0.8];
        
    }];
    
}

#pragma mark - 获取网络数据

-(void)loadData{
    
    
    NSString * url = @"http://iosapi.itcast.cn/doctorList.json.php";
    NSDictionary *parameter = @{@"user_id":@1000089,@"page_size":@15,@"page":@1};


    
  [HMDoctorListModel getDocListDataWithURLString:url andParameters:parameter andSuccessBlock:^(NSArray *newsList) {
        
        self.docList = newsList;
        
        [self.tableView reloadData];
        
    } andErrorBlock:^(NSError *error) {
        NSLog(@"error = %@",error);
    }];
    
    
    

    
    
}




#pragma mark - 数据源方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.docList.count;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
  
   
   HMDoctorListCell*cell = [tableView dequeueReusableCellWithIdentifier:DOCCELL forIndexPath:indexPath];
  
    cell.doctorModel = self.docList[indexPath.row];
 
    return cell;
}



//cell点击
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"HMDocDetailView" bundle:nil];
    HMDocDetailController*detailVc = [story instantiateInitialViewController];
    

    detailVc.docListModel =_docList[indexPath.row];
    
   
    //点击进行push
    [self.navigationController pushViewController:detailVc animated:YES];
    
    self.hidesBottomBarWhenPushed=YES;
    
    
}


@end
